package com.example.hello.service;

import java.util.List;

import org.springframework.stereotype.Service;

import com.example.hello.entity.WorkOrder;
import com.example.hello.mapper.WorkOrderMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class WorkOrderService {
    private final WorkOrderMapper workOrderMapper;

    public WorkOrderService(WorkOrderMapper workOrderMapper) {
        this.workOrderMapper = workOrderMapper;
    }

    public WorkOrder createWorkOrder(WorkOrder workOrder) {
        workOrderMapper.insert(workOrder);
        return workOrder;
    }

    public WorkOrder updateWorkOrderStatus(Integer workOrderId, String status) {
        workOrderMapper.updateStatus(workOrderId, status);
        return workOrderMapper.findById(workOrderId);
    }

    public PageInfo<WorkOrder> getWorkOrders(String status, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<WorkOrder> workOrders = workOrderMapper.findByStatus(status);
        return new PageInfo<>(workOrders);
    }

    public WorkOrder getWorkOrderDetail(Integer workOrderId) {
        return workOrderMapper.findById(workOrderId);
    }
} 